//
//  HJSelectFridendCell.m
//  KaiChat
//
//  Created by lx on 2023/11/2.
//

#import "HJSelectFridendCell.h"

@interface HJSelectFridendCell()

@property (nonatomic, weak) UIImageView *avatarImageView;
@property (nonatomic, weak) UIButton *boxButton;
@property (nonatomic, weak) UILabel *nameLabel;


@end

@implementation HJSelectFridendCell

- (void)settingSubView {
    [super settingSubView];
    
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIButton *boxButton = [UIButton addToView:self.contentView];
    boxButton.userInteractionEnabled = NO;
    [boxButton setBackgroundImage:[UIImage imageNamed:@"box_icon"] forState:UIControlStateNormal];
    [boxButton setBackgroundImage:[UIImage imageNamed:@"box_select_icon"] forState:UIControlStateSelected];
    [boxButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(leftRightMargin);
        make.centerY.offset(0);
        make.width.height.offset(20);
    }];
    
    UIImageView *avatarImageView = [UIImageView addToView:self.contentView];
    avatarImageView.addCornerRadius(20);
    avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
    [avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(boxButton.mas_right).offset(10);
        make.centerY.offset(0);
        make.width.height.offset(40);
    }];
 
    UILabel *nameLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(14) color:UIColor.tj_333333Color title:nil textAlignment:NSTextAlignmentLeft];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(avatarImageView.mas_right).offset(10);
        make.centerY.offset(0);
        make.right.mas_lessThanOrEqualTo(-16);
    }];
    
    _boxButton = boxButton;
    _avatarImageView = avatarImageView;
    _nameLabel = nameLabel;
}


- (void)setModel:(HJChatFriendModel *)model {
    _model = model;
    
    _boxButton.selected = model.isSelect;
    _nameLabel.text = model.showName;
    if (isEmptyString(model.avatar)) {
        _avatarImageView.image = [UIImage imageNamed:defaultAvatarName];
    } else {
        [_avatarImageView sd_setImageWithURL:model.avatar.URL placeholderImage:[UIImage imageNamed:defaultAvatarName]];
    }
     
}


@end
